package com.yht.framework.common.utils;

import java.util.regex.Pattern;

/**
 * 用户信息校验
 */
public class ParamUtils {

    private ParamUtils() {

    }

    //======================= 昵称校验 =======================
    private static final int NICK_NAME_MIN_LENGTH = 2;

    private static final int NICK_NAME_MAX_LENGTH = 24;

    //======================= 昵称特殊字符正则匹配 =======================
    private static final String NICK_NAME_REGEX = "[!@#$%^&*(),.?\":{}|<>]";


    //======================= ID 校验 =======================
    private static final int ID_MIN_LENGTH = 6;

    private static final int ID_MAX_LENGTH = 15;

    //======================= 昵称特殊字符正则匹配 =======================
    private static final String ID_REGEX = "^[a-zA-Z0-9_]+$";

    /**
     * 校验用户昵称
     *
     * @param nickname
     * @return
     */
    public static boolean checkNickname(String nickname) {

        if (nickname.length() < NICK_NAME_MIN_LENGTH || nickname.length() > NICK_NAME_MAX_LENGTH) {
            return false;
        }

        Pattern pattern = Pattern.compile(NICK_NAME_REGEX);
        return !pattern.matcher(nickname).find();
    }

    /**
     * 校验用户 xiaohashu ID
     *
     * @param id
     * @return
     */
    public static boolean checkXiaohashuId(String id) {
        if (id.length() < ID_MIN_LENGTH || id.length() > ID_MAX_LENGTH) {
            return false;
        }

        Pattern pattern = Pattern.compile(ID_REGEX);
        return pattern.matcher(id).matches();

    }

    /**
     * 校验字符串长度
     *
     * @param str
     * @param length
     * @return
     */
    public static boolean checkLength(String str, int length) {
        if (str.isEmpty() || str.length() > length) {
            return false;
        }
        return true;
    }
}


